/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webanovare.bb;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;

/**
 * Holds chat messages.
 */
@ManagedBean(name = "messageBean")
@ApplicationScoped
public class MessageBB implements Serializable {
    private List<String> textList = new LinkedList<>();
    private static int MAX_SIZE = 50;
    
    public MessageBB() {
    }

    public List<String> getTextList() {
        return textList;
    }

    public void setTextList(List<String> textList) {
        this.textList = textList;
    }

    public void addToList(String userName, String text) {
        textList.add(userName + ": " + text);

        while (textList.size() > MAX_SIZE) {
            textList.remove(0);
        }
    }
}